/*CVS-LEXER*/
%{
#include <iostream>
#include <string>
using namespace std;

#include "Libcvs.tab.hh"
#include "Libcvs.hh"

/* import the parser's token type into a local typedef */
typedef Libcvs::LibcvsBisonParser::token token;
typedef Libcvs::LibcvsBisonParser::token_type token_type;

/* By default yylex returns int, we use token_type. 
 * Unfortunately yyterminate by default returns 0, which is not of token_type.
 */
#define yyterminate() return token::END

string data="";
%}

/*** Flex Declarations and Options ***/
%option prefix="Libcvs"
%option nodefault noyywrap yyclass="Libcvs::LibcvsFlexScanner" 
/* enable c++ scanner class generation */
%option c++
/* the manual says "somewhat more optimized" */		
%option batch
/* enables the use of start condition stacks */ 
%option stack

%%

"<?xml version=\"1.0\"?>"                                               {return token::XMLHEADER;}
"<changelog xmlns=\"http://www.red-bean.com/xmlns/cvs2cl/\">"           {return token::BCHANGELOG;}
"</changelog>"          {return token::ECHANGELOG;}
"<entry>"               {return token::BENTRY;}
"</entry>"              {yylval->stringVal = new std::string(data); return token::EENTRY;}
"<date>"                { data=""; return token::BDATE;}
"</date>"               {yylval->stringVal = new std::string(data); return token::EDATE;}
"<weekday>"             { data=""; return token::BWEEK;}
"</weekday>"            {yylval->stringVal = new std::string(data); return token::EWEEK;}
"<time>"                { data=""; return token::BTIME;}
"</time>"               {yylval->stringVal = new std::string(data); return token::FTIME;}
"<isoDate>"             { data=""; return token::BISO;}
"</isoDate>"            {yylval->stringVal = new std::string(data); return token::EISO;}
"<author>"              { data=""; return token::BAUTHOR;}
"</author>"             {yylval->stringVal = new std::string(data); return token::EAUTHOR;}
"<file>"                { data=""; return token::BFILE;}
"</file>"               {yylval->stringVal = new std::string(data); return token::EFILE;}
"<name>"                { data=""; return token::BNAME;}
"</name>"               {yylval->stringVal = new std::string(data); return token::ENAME;}
"<cvsstate>"            { data=""; return token::BCVSSTATE;}
"</cvsstate>"           {yylval->stringVal = new std::string(data); return token::ECVSSTATE;}
"<revision>"            { data=""; return token::BREVISION;}
"</revision>"           {yylval->stringVal = new std::string(data); return token::EREVISION;}
"<tag>"                 { data=""; return token::BTAG;}
"</tag>"                {yylval->stringVal = new std::string(data); return token::ETAG;}
"<msg>"                 { data=""; return token::BMSG;}
"</msg>"                {yylval->stringVal = new std::string(data); return token::EMSG;}
"<commondir>"           { data=""; return token::BCOMMONDIR;}
"</commondir>"          {yylval->stringVal = new std::string(data); return token::ECOMMONDIR;}
"<tagisodate>"          { data=""; return token::BTAGISODATE;}
"</tagisodate>"         {yylval->stringVal = new std::string(data); return token::ETAGISODATE;}
"<tagdatetag>"          { data=""; return token::BTAGDATETAG;}
"</tagdatetag>"         {yylval->stringVal = new std::string(data); return token::ETAGDATETAG;}
"<tagdate>"             { data=""; return token::BTAGDATE;}
"</tagdate>"            {yylval->stringVal = new std::string(data); return token::ETAGDATE;}
"<branch>"             	{ data=""; return token::BBRANCH;}
"</branch>"            	{yylval->stringVal = new std::string(data); return token::EBRANCH;}
.|\n                    {data+=string(yytext);}

%%
